批量修改时间文件创建时间/文件修改日期 private ChangeTypeEnum cte;
public ChangeTime()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
FolderBrowserDialog path = new FolderBrowserDialog();
path.ShowDialog();
this.textBox1.Text = path.SelectedPath;
}
private void button2_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(comboBox1.Text))
{
MessageBox.Show("请选类型");
return;
}
cte = (ChangeTypeEnum)Enum.Parse(typeof(ChangeTypeEnum), comboBox1.Text);
//获取需要修改的时间
DateTime dt = dateTimePicker1.Value.Date;
dt.AddHours((double)numericUpDown1.Value);
dt.AddMinutes((double)numericUpDown2.Value);
dt.AddSeconds((double)numericUpDown3.Value);
GetFilesByDir(this.textBox1.Text);
foreach (FileInfo fi in fileInfos)
{
switch (cte)
{
case ChangeTypeEnum.创建日期:
listBox1.Items.Add($"文件名{fi.Name} 原始时间:{fi.CreationTime.ToString()}修改后时间:{dt.ToString()}");
fi.CreationTime = dt;
break;
case ChangeTypeEnum.修改时间:
listBox1.Items.Add($"文件名{fi.Name} 原始时间:{fi.CreationTime.ToString()}修改后时间:{dt.ToString()}");
fi.LastWriteTimeUtc = dt;
break;
default:
fi.CreationTime = dt;
fi.LastWriteTimeUtc = dt;
break;
}
}
MessageBox.Show("修改完成");
}
评论